/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package simulation;

import java.awt.AWTEvent;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Observable;
import java.util.Observer;
import javax.swing.JComboBox;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.table.TableModel;
import logging.LogSetup;
import org.apache.log4j.Logger;

/**
 *
 * @author Danielondon
 */
public class SimulationView extends javax.swing.JFrame implements Observer {
    protected Logger logger = LogSetup.getLogger();
    private int slotsPerHour = 4; // amount
    private int totalHours = 24; // It may be per daily basis
    private int TOTAL_SLOTS;
    private SimulationControllerAgent controller;
    private String EXTENSION_DRIVING_PATTERNS = ".csv_dp";
    private String EXTENSION_CAR_SPECS = ".txt_cs";    
    private String EXTENSION_PLOT = ".plt";
    private String EXTENSION_DATA = ".csv";
    /**
     * Creates new form SimulationView
     */
    public SimulationView(SimulationControllerAgent controller) {
        this();
        this.controller = controller;
    }

    public SimulationView(){
        initComponents();
        this.calculateTotalTime();
        this.loadCarSpecs();
        this.loadDrivingPatterns();
        this.loadMarket();
        this.loadSimulationResults();
        this.loadStrategies();
    }
    
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        buttonGroup2 = new javax.swing.ButtonGroup();
        buttonGroup3 = new javax.swing.ButtonGroup();
        buttonGroup4 = new javax.swing.ButtonGroup();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jButton1 = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        jLabelMarketStatus = new javax.swing.JLabel();
        jComboBoxDrivingPatterns = new javax.swing.JComboBox();
        jLabel3 = new javax.swing.JLabel();
        jComboBoxChargingStrategies = new javax.swing.JComboBox();
        jLabel7 = new javax.swing.JLabel();
        jLabelTotalSlots = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jTextFieldSlotsPerHour = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jButtonSetSimulation = new javax.swing.JButton();
        jButtonStartSimulation = new javax.swing.JButton();
        jTextFieldFileName = new javax.swing.JTextField();
        jButtonSaveResults = new javax.swing.JButton();
        jLabel8 = new javax.swing.JLabel();
        jButtonOneForEachPattern = new javax.swing.JButton();
        jLabelTotalHours = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jComboBoxMarket = new javax.swing.JComboBox();
        jLabel1 = new javax.swing.JLabel();
        jComboBoxCarModels = new javax.swing.JComboBox();
        jPanel2 = new javax.swing.JPanel();
        jLabel10 = new javax.swing.JLabel();
        jTextFieldInitalPrice = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        jTextFieldEndPrice = new javax.swing.JTextField();
        jTextFieldMarketFile = new javax.swing.JTextField();
        jButtonCreateMarketData = new javax.swing.JButton();
        jRadioButtonTwoModalPrice = new javax.swing.JRadioButton();
        jRadioButtonLinearModel = new javax.swing.JRadioButton();
        jTextFieldStartModalPrice = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        jTextFieldEndModalPrice = new javax.swing.JTextField();
        jLabel15 = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        jCheckBoxHome = new javax.swing.JCheckBox();
        jCheckBoxGreedy = new javax.swing.JCheckBox();
        jButtonReloadPrices = new javax.swing.JButton();
        jButtonFirstTen = new javax.swing.JButton();
        jButtonChangeStrategy = new javax.swing.JButton();
        jButtonOpenResults = new javax.swing.JButton();
        jComboBoxPlotResults = new javax.swing.JComboBox();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ));
        jTable1.setDoubleBuffered(true);
        jScrollPane1.setViewportView(jTable1);

        jButton1.setText("Single Agent");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jLabel2.setText("Is Market Ready?");

        jLabelMarketStatus.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabelMarketStatus.setText("NO");
        jLabelMarketStatus.setToolTipText("");

        jComboBoxDrivingPatterns.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "drivingPattern1.csv", "drivingPattern2.csv" }));

        jLabel3.setText("Driving Pattern:");

        jLabel7.setText("Solver / Charge Strategy");

        jLabelTotalSlots.setText("96");

        jLabel4.setText("Slots per Hour");

        jTextFieldSlotsPerHour.setText("4");
        jTextFieldSlotsPerHour.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldSlotsPerHourActionPerformed(evt);
            }
        });
        jTextFieldSlotsPerHour.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                jTextFieldSlotsPerHourFocusLost(evt);
            }
        });

        jLabel6.setText("Total Slots");

        jLabel5.setText("Total Hours");

        jButtonSetSimulation.setBackground(new java.awt.Color(255, 53, 54));
        jButtonSetSimulation.setText("Set Simulation");
        jButtonSetSimulation.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonSetSimulationActionPerformed(evt);
            }
        });

        jButtonStartSimulation.setBackground(new java.awt.Color(255, 255, 102));
        jButtonStartSimulation.setText("Start Simulation");
        jButtonStartSimulation.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonStartSimulationActionPerformed(evt);
            }
        });

        jTextFieldFileName.setText("simulation_results");
        jTextFieldFileName.setToolTipText("");

        jButtonSaveResults.setBackground(new java.awt.Color(0, 162, 0));
        jButtonSaveResults.setText("Save Results");
        jButtonSaveResults.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonSaveResultsActionPerformed(evt);
            }
        });

        jLabel8.setText(".CSV");

        jButtonOneForEachPattern.setText("Agent per Pattern");
        jButtonOneForEachPattern.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonOneForEachPatternActionPerformed(evt);
            }
        });

        jLabelTotalHours.setText("24");

        jLabel9.setText("Price Signal:");

        jLabel1.setText("Car Specs:");

        jComboBoxCarModels.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "carSpecs1.txt", "carSpecs2.txt" }));

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jTextFieldSlotsPerHour, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabelTotalHours))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel6)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabelTotalSlots))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabelMarketStatus)))
                .addGap(29, 29, 29)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel9)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jComboBoxMarket, javax.swing.GroupLayout.PREFERRED_SIZE, 164, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel7)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jComboBoxChargingStrategies, javax.swing.GroupLayout.PREFERRED_SIZE, 164, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel3)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jComboBoxDrivingPatterns, javax.swing.GroupLayout.PREFERRED_SIZE, 164, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jButtonOneForEachPattern)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jComboBoxCarModels, javax.swing.GroupLayout.PREFERRED_SIZE, 164, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(27, 27, 27)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jTextFieldFileName)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel8))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jButtonSaveResults, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jButtonStartSimulation, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jButtonSetSimulation, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 123, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(358, 358, 358))
        );

        jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jLabel2, jLabel4, jLabel5, jLabel6});

        jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jLabelMarketStatus, jLabelTotalHours, jLabelTotalSlots, jTextFieldSlotsPerHour});

        jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jLabel1, jLabel3, jLabel7, jLabel9});

        jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jComboBoxCarModels, jComboBoxChargingStrategies, jComboBoxDrivingPatterns, jComboBoxMarket});

        jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jButton1, jButtonOneForEachPattern, jButtonSaveResults, jButtonSetSimulation, jButtonStartSimulation});

        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jTextFieldSlotsPerHour, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel4)
                            .addComponent(jLabel3)
                            .addComponent(jComboBoxDrivingPatterns, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel5)
                            .addComponent(jLabelTotalHours))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel6)
                            .addComponent(jLabelTotalSlots))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(jLabelMarketStatus)
                            .addComponent(jLabel1)
                            .addComponent(jComboBoxCarModels, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jButtonSetSimulation)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(25, 25, 25)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jButtonStartSimulation)
                                    .addComponent(jButtonOneForEachPattern)
                                    .addComponent(jComboBoxChargingStrategies, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel7))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(jTextFieldFileName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jLabel8))
                                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(jLabel9)
                                        .addComponent(jComboBoxMarket, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButtonSaveResults)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 463, Short.MAX_VALUE))
        );

        jPanel1Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {jLabel2, jLabel4, jLabel5, jLabel6});

        jPanel1Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {jButtonSaveResults, jButtonSetSimulation, jButtonStartSimulation});

        jButton1.getAccessibleContext().setAccessibleName("Start Agent");

        jTabbedPane1.addTab("Simulation", jPanel1);

        jLabel10.setText("Initial Price / Night Price");

        jTextFieldInitalPrice.setText("56.00");

        jLabel11.setText("End Price / Day Price");

        jTextFieldEndPrice.setText("56.00");

        jTextFieldMarketFile.setText("FILE_NAME");

        jButtonCreateMarketData.setText("Create Market Data");
        jButtonCreateMarketData.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonCreateMarketDataActionPerformed(evt);
            }
        });

        buttonGroup1.add(jRadioButtonTwoModalPrice);
        jRadioButtonTwoModalPrice.setText("Two Modal Price");

        buttonGroup1.add(jRadioButtonLinearModel);
        jRadioButtonLinearModel.setSelected(true);
        jRadioButtonLinearModel.setText("Linear Model");

        jTextFieldStartModalPrice.setText("30");

        jLabel12.setText("%");

        jLabel13.setText("Start");

        jLabel14.setText("End");

        jTextFieldEndModalPrice.setText("75");

        jLabel15.setText("%");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jRadioButtonLinearModel)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(jRadioButtonTwoModalPrice)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jLabel13)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTextFieldStartModalPrice, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel12)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jLabel14)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTextFieldEndModalPrice, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel15))))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel10)
                                    .addComponent(jLabel11))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jTextFieldEndPrice, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jTextFieldInitalPrice, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel2Layout.createSequentialGroup()
                                .addComponent(jTextFieldMarketFile, javax.swing.GroupLayout.PREFERRED_SIZE, 149, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jButtonCreateMarketData, javax.swing.GroupLayout.PREFERRED_SIZE, 149, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addContainerGap(886, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel10)
                    .addComponent(jTextFieldInitalPrice, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel11)
                    .addComponent(jTextFieldEndPrice, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jRadioButtonTwoModalPrice)
                    .addComponent(jTextFieldStartModalPrice, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel12)
                    .addComponent(jLabel13)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jTextFieldEndModalPrice, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel15)
                        .addComponent(jLabel14)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jRadioButtonLinearModel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextFieldMarketFile, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButtonCreateMarketData))
                .addContainerGap(427, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Market", jPanel2);

        jCheckBoxHome.setSelected(true);
        jCheckBoxHome.setText("Home");

        jCheckBoxGreedy.setText("Greedy");

        jButtonReloadPrices.setText("Reload Prices");
        jButtonReloadPrices.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonReloadPricesActionPerformed(evt);
            }
        });

        jButtonFirstTen.setText("10X");
        jButtonFirstTen.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonFirstTenActionPerformed(evt);
            }
        });

        jButtonChangeStrategy.setText("Change Strategy");
        jButtonChangeStrategy.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonChangeStrategyActionPerformed(evt);
            }
        });

        jButtonOpenResults.setText("Open Results");
        jButtonOpenResults.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonOpenResultsActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGap(269, 269, 269)
                        .addComponent(jCheckBoxHome)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jCheckBoxGreedy))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGap(139, 139, 139)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jPanel3Layout.createSequentialGroup()
                                .addComponent(jButtonFirstTen, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jButtonReloadPrices))
                            .addComponent(jButtonChangeStrategy)
                            .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(jComboBoxPlotResults, javax.swing.GroupLayout.PREFERRED_SIZE, 164, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jButtonOpenResults, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addContainerGap(815, Short.MAX_VALUE))
        );

        jPanel3Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jButtonOpenResults, jComboBoxPlotResults});

        jPanel3Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jButtonChangeStrategy, jButtonFirstTen, jButtonReloadPrices});

        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jCheckBoxHome)
                    .addComponent(jCheckBoxGreedy))
                .addGap(18, 18, 18)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButtonFirstTen)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jButtonReloadPrices, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButtonChangeStrategy, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(18, 18, 18)
                .addComponent(jComboBoxPlotResults, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonOpenResults)
                .addContainerGap(412, Short.MAX_VALUE))
        );

        jPanel3Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {jButtonChangeStrategy, jButtonReloadPrices});

        jTabbedPane1.addTab("Extras", jPanel3);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 1205, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 601, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
        );

        jTabbedPane1.getAccessibleContext().setAccessibleName("Simulation");

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
        if (this.controller != null){
            this.controller.doDelete();
        } else {
            this.dispose();
        }
    }//GEN-LAST:event_formWindowClosing

    private void jButtonChangeStrategyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonChangeStrategyActionPerformed
        int [] indexes = this.jTable1.getSelectedRows();
        String newStrategy = (String)jComboBoxChargingStrategies.getSelectedItem();
        this.controller.changeChargeStrategy(newStrategy, indexes);
    }//GEN-LAST:event_jButtonChangeStrategyActionPerformed

    private void jButtonOpenResultsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonOpenResultsActionPerformed
        String fileName = (String)this.jComboBoxPlotResults.getSelectedItem();
        String script = "wgnuplot \"" + fileName + "\"" + " -persist -pause";
        //String script = "wgnuplot";
        //script = "open.bat";

        ArrayList list = new ArrayList();
        list.add("wgnuplot");
        list.add("\"" + fileName + "\"");
        list.add("-pause");
        String[] Command = (String[]) list.toArray(new String[0]);

        Runtime run = Runtime.getRuntime();

        try {
            String [] params = new String[1];
            params[0] = "-pause";
            //Process p = run.exec(script);//,params);
        //Process aProcess = Runtime.getRuntime().exec(script);
        //Thread.currentThread().sleep(1000);
        //aProcess.waitFor();
        ProcessBuilder builder = new ProcessBuilder(script);
        builder.redirectErrorStream(true);

        Process process = builder.start();

        } catch (IOException e) {
            logger.error("Error starting script ", e);
            return;
        }
    }//GEN-LAST:event_jButtonOpenResultsActionPerformed

    private void jButtonOneForEachPatternActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonOneForEachPatternActionPerformed
        this.addCarPerDrivingPattern(-1);
    }//GEN-LAST:event_jButtonOneForEachPatternActionPerformed

    private void jButtonSaveResultsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonSaveResultsActionPerformed
        if (controller.saveResults(this.jTextFieldFileName.getText(), EXTENSION_DATA, EXTENSION_PLOT)){
            infoBox("File was saved succesfully", "Success");
            this.loadSimulationResults();
        } else{
            infoBox("File could not be saved.", "Error");
        }
    }//GEN-LAST:event_jButtonSaveResultsActionPerformed

    private void jButtonStartSimulationActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonStartSimulationActionPerformed
        this.controller.startSimulation();
    }//GEN-LAST:event_jButtonStartSimulationActionPerformed

    private void jButtonSetSimulationActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonSetSimulationActionPerformed
        String marketFile = (String)jComboBoxMarket.getSelectedItem();
        this.controller.setSimulation(this.TOTAL_SLOTS, this.slotsPerHour, marketFile);
    }//GEN-LAST:event_jButtonSetSimulationActionPerformed

    private void jTextFieldSlotsPerHourFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTextFieldSlotsPerHourFocusLost
        this.adjustSlotCount(evt);
    }//GEN-LAST:event_jTextFieldSlotsPerHourFocusLost

    private void jTextFieldSlotsPerHourActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldSlotsPerHourActionPerformed
        this.adjustSlotCount(evt);
    }//GEN-LAST:event_jTextFieldSlotsPerHourActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        this.addCar(1);
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButtonReloadPricesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonReloadPricesActionPerformed
        this.loadMarket();
    }//GEN-LAST:event_jButtonReloadPricesActionPerformed

    private void jButtonFirstTenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonFirstTenActionPerformed
        this.addCarPerDrivingPattern(10);
    }//GEN-LAST:event_jButtonFirstTenActionPerformed

    private void jButtonCreateMarketDataActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCreateMarketDataActionPerformed
        try {
            double dayPrice = Double.valueOf(this.jTextFieldInitalPrice.getText()); 
            double endPrice = Double.valueOf(this.jTextFieldEndPrice.getText());
            boolean isDualPriceModel = this.jRadioButtonTwoModalPrice.isSelected();
            if (this.jTextFieldMarketFile.getText().equals(""))
                throw new Exception("No file name given");
            double startModalPrice = Double.valueOf(this.jTextFieldStartModalPrice.getText());
            double endModalPrice = Double.valueOf(this.jTextFieldEndModalPrice.getText());
            startModalPrice = startModalPrice / 100.0;
            endModalPrice = endModalPrice / 100.0;
            this.controller.createMarketData(this.jTextFieldMarketFile.getText(), dayPrice, endPrice, this.TOTAL_SLOTS, isDualPriceModel, startModalPrice, endModalPrice);
            this.loadMarket();
            this.infoBox("Market data created succesfully", "Marked Data created");
        } catch (Exception ex){
            this.infoBox(ex.getMessage(), "Error creating market data");
        }
    }//GEN-LAST:event_jButtonCreateMarketDataActionPerformed

    public void infoBox(String infoMessage, String title){
        JOptionPane.showMessageDialog(null, infoMessage, "InfoBox: " + title, JOptionPane.INFORMATION_MESSAGE);
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new SimulationView().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.ButtonGroup buttonGroup2;
    private javax.swing.ButtonGroup buttonGroup3;
    private javax.swing.ButtonGroup buttonGroup4;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButtonChangeStrategy;
    private javax.swing.JButton jButtonCreateMarketData;
    private javax.swing.JButton jButtonFirstTen;
    private javax.swing.JButton jButtonOneForEachPattern;
    private javax.swing.JButton jButtonOpenResults;
    private javax.swing.JButton jButtonReloadPrices;
    private javax.swing.JButton jButtonSaveResults;
    private javax.swing.JButton jButtonSetSimulation;
    private javax.swing.JButton jButtonStartSimulation;
    private javax.swing.JCheckBox jCheckBoxGreedy;
    private javax.swing.JCheckBox jCheckBoxHome;
    private javax.swing.JComboBox jComboBoxCarModels;
    private javax.swing.JComboBox jComboBoxChargingStrategies;
    private javax.swing.JComboBox jComboBoxDrivingPatterns;
    private javax.swing.JComboBox jComboBoxMarket;
    private javax.swing.JComboBox jComboBoxPlotResults;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JLabel jLabelMarketStatus;
    private javax.swing.JLabel jLabelTotalHours;
    private javax.swing.JLabel jLabelTotalSlots;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JRadioButton jRadioButtonLinearModel;
    private javax.swing.JRadioButton jRadioButtonTwoModalPrice;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JTextField jTextFieldEndModalPrice;
    private javax.swing.JTextField jTextFieldEndPrice;
    private javax.swing.JTextField jTextFieldFileName;
    private javax.swing.JTextField jTextFieldInitalPrice;
    private javax.swing.JTextField jTextFieldMarketFile;
    private javax.swing.JTextField jTextFieldSlotsPerHour;
    private javax.swing.JTextField jTextFieldStartModalPrice;
    // End of variables declaration//GEN-END:variables

    public void showGui() {
        pack();
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        int centerX = (int)screenSize.getWidth() / 2;
        int centerY = (int)screenSize.getHeight() / 2;
        setLocation(centerX - getWidth() / 2, centerY - getHeight() / 2);
        super.setVisible(true);
    }

    @Override
    public void update(Observable o, Object arg) { 
        SimulationModel model = (SimulationModel)o;
        TableModel tableModel = model.getTableModel();
        if (this.jTable1.getColumnCount() == 0){
            this.jTable1.setModel(tableModel);          
        }
        
        this.jTable1.repaint();
        
        if (model.isMarketReady())
            this.jLabelMarketStatus.setText("YES");
        else
            this.jLabelMarketStatus.setText("NO");
        
        if (model.isSimulationStarted()) {
            this.jTextFieldSlotsPerHour.setEditable(false);
        } else {
            this.jTextFieldSlotsPerHour.setEditable(true);
        }
    }
    
    private void calculateTotalTime() {
        this.TOTAL_SLOTS = this.slotsPerHour * this.totalHours;
        this.jLabelTotalSlots.setText(TOTAL_SLOTS + "");
    }
    

    private void addCar(int count) {
        String carSpecs = (String)this.jComboBoxCarModels.getSelectedItem();
        String drivingPattern = (String)this.jComboBoxDrivingPatterns.getSelectedItem();
        String chargingStrategy = (String)this.jComboBoxChargingStrategies.getSelectedItem();
        controller.addCar(carSpecs, drivingPattern, chargingStrategy, count);
    }
    
    public List<File> listFiles(File rootDir, FileFilter filter) {
        List<File> result = new ArrayList<File>();
        if( !rootDir.exists() || !rootDir.isDirectory() ) 
            return result;


        //Add all files that comply with the given filter
        File[] files = rootDir.listFiles(filter);
        for( File f : files) {
            if( !result.contains(f) )
                result.add(f);
        }

        return result;
    }

    private void loadCarSpecs() {
        loadComboBox(this.jComboBoxCarModels, EXTENSION_CAR_SPECS);
    }
    
    private void loadDrivingPatterns(){
        loadComboBox(this.jComboBoxDrivingPatterns, EXTENSION_DRIVING_PATTERNS);
    }
    
    private void loadMarket(){
        loadComboBox(this.jComboBoxMarket, MarketFactory.EXTENSION_MARKET);
    }

    private void loadComboBox(JComboBox jComboBox, final String extension) {
        jComboBox.removeAllItems();
        File directory = new File (".");
        FileFilter filter = new FileFilter() {
            public boolean accept(File file) {
                return file.getName().endsWith(extension);
            }
        };
        
        List<File> files = this.listFiles(directory, filter);
        for (File f:files){
            jComboBox.addItem(f.getName());
        }
    }

    private void adjustSlotCount(AWTEvent evt) {
        JTextField textField = ((JTextField)evt.getSource());
        String text = textField.getText();
        try {
            slotsPerHour = Integer.parseInt(text);
            calculateTotalTime();
        } catch(Exception ex) {
            textField.setText(slotsPerHour + "");
        }
    }

    private void addCarPerDrivingPattern(int count) {
        if (count == -1)
             count = this.jComboBoxDrivingPatterns.getItemCount();
        String carSpecs = (String)this.jComboBoxCarModels.getSelectedItem();
        String chargingStrategy = (String)this.jComboBoxChargingStrategies.getSelectedItem();
        int total  = this.jComboBoxDrivingPatterns.getItemCount();
        int countAdded = 0;
        for (int i = 0; countAdded < count && i < total; i++){
            String drivingPattern = (String)this.jComboBoxDrivingPatterns.getItemAt(i);
            if (matchOptions(drivingPattern)){
                controller.addCar(carSpecs, drivingPattern, chargingStrategy, 1);
                countAdded++;
            }
        }
    }

    private void loadStrategies() {
        this.jComboBoxChargingStrategies.removeAllItems();
        for (String strategy:ChargeStrategyFactory.CHARGE_STRATEGIES){
            this.jComboBoxChargingStrategies.addItem(strategy);
        }
    }

    private void loadSimulationResults() {
        this.loadComboBox(this.jComboBoxPlotResults, EXTENSION_PLOT);
    }

    private boolean matchOptions(String drivingPattern) {
        if (drivingPattern.toLowerCase().contains("home") && this.jCheckBoxHome.isSelected())
            return true;
        if (drivingPattern.toLowerCase().contains("greedy") && this.jCheckBoxGreedy.isSelected())
            return true;
        
        return false;
    }
}
